from selenium.webdriver.support.wait import WebDriverWait
from appium.webdriver.common.appiumby import By

class AddCart:
    def add_cart(self, driver):
        WebDriverWait(driver, 10).until(lambda x: x.find_element(By.ID, "com.tpshop.malls:id/add_cart_tv")).click()
        WebDriverWait(driver, 10).until(lambda x: x.find_element(by=By.XPATH, value="//*[@text='套餐一']")).click()
        WebDriverWait(driver, 10).until(lambda x: x.find_element(by=By.XPATH, value="//*[@text='幻夜色']")).click()
        WebDriverWait(driver, 10).until(lambda x: x.find_element(by=By.XPATH, value="//*[@text='全网通4G+64G']")).click()
        # 滑动界面
        driver.swipe(start_x=740, start_y=1660, end_x=720, end_y=1200)
        for i in range(3):
            WebDriverWait(driver, 10).until(lambda x: x.find_element(by=By.ID, value="com.tpshop.malls:id/cart_plus_btn")).click()
        WebDriverWait(driver, 10).until(lambda x: x.find_element(by=By.ID, value="com.tpshop.malls:id/confirm_tv")).click()
